//
//  LHTopView.swift
//  sinaWeibo
//
//  Created by LiHong on 15/11/1.
//  Copyright © 2015年 LiHong. All rights reserved.
//

import UIKit

class LHTopView: UIView {
    
    //MARK: - 微博模型
    var statuses: LHStatus?{
        didSet{
            if let iconUrl = statuses?.user?.profile_image_url{
                iconView.lh_setImageWithURL(NSURL(string: iconUrl))
            }
            nameLabel.text = statuses?.user?.name!
            sourceLabel.text = "来自 ** 微博"
            timeLabel.text = statuses?.created_at
            verifiedView.image = statuses?.user?.verifiedTypeImage
            memberView.image = statuses?.user?.mbrankImage
            
            
            
        }
    }
    
    //MARK: - 构造方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        prepareUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    //MARK: - 准备UI
    private func prepareUI() {
        addSubview(topSeparatorView)
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(verifiedView)
        addSubview(memberView)
        // 添加约束
        // 头部分割视图
        topSeparatorView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 10))
        // 头像
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: topSeparatorView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 8, y: 8))
        // 名称
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        // 时间
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        // 来源
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: timeLabel, size: nil, offset: CGPoint(x: 8, y: 0))
        // 认证图标
        verifiedView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: CGSize(width: 17, height: 17), offset: CGPoint(x: 8.5, y: 8.5))
        // 会员等级
        memberView.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: nameLabel, size: CGSize(width: 14, height: 14), offset: CGPoint(x: 8, y: 0))
        
        
    }
    
    
    //MARK: - 懒加载
   
    
    /// 顶部分割视图
    private lazy var topSeparatorView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(white: 0.9, alpha: 1)
        return view
    }()
    
    /// 用户头像
    private lazy var iconView = UIImageView()
    
    /// 用户名称
    private lazy var nameLabel = UILabel(fontSize: 14, textColor: UIColor.darkGrayColor())
    
    /// 时间label
    private lazy var timeLabel = UILabel(fontSize: 9, textColor: UIColor.orangeColor())
    
    /// 来源
    private lazy var sourceLabel = UILabel(fontSize: 9, textColor: UIColor.lightGrayColor())
    
    /// 认证图标
    private lazy var verifiedView = UIImageView()
    
    /// 会员等级
    private lazy var memberView = UIImageView()
    
}
